package com.ruoyi.project.zerocarbon.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.zerocarbon.domain.DeclareJudge;
import com.ruoyi.project.zerocarbon.domain.DeclareRanking;
import com.ruoyi.project.zerocarbon.service.IDeclareJudgeService;
import com.ruoyi.project.zerocarbon.service.IDeclareRankingService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 排名Controller
 * 
 * @author ruoyi
 * @date 2021-07-31
 */
@RestController
@RequestMapping("/zerocarbon/ranking")
public class DeclareRankingController extends BaseController
{
    @Autowired
    private IDeclareJudgeService declareJudgeService;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private IDeclareRankingService declareRankingService;

    /**
     * 查询排名列表
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:ranking:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeclareRanking declareRanking)
    {
        startPage();
        List<DeclareRanking> list = declareRankingService.selectDeclareRankingList(declareRanking);
        return getDataTable(list);
    }

    /**
     * 导出排名列表
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:ranking:export')")
    @Log(title = "排名", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DeclareRanking declareRanking)
    {
        List<DeclareRanking> list = declareRankingService.selectDeclareRankingList(declareRanking);
        ExcelUtil<DeclareRanking> util = new ExcelUtil<DeclareRanking>(DeclareRanking.class);
        return util.exportExcel(list, "排名数据");
    }

    /**
     * 新增项目评审
     */
    @ApiOperation("排名列表:评审查看(根据项目类型和评审员userId)")
    @PostMapping("/view")
    public AjaxResult view(@RequestBody DeclareJudge declareJudge)
    {
        Assert.notNull(declareJudge.getExpertNumber());
        DeclareJudge judge = new DeclareJudge();
        judge.setUserId(declareJudge.getUserId());
        //        judge.setExpertName(declareJudge.getExpertName());
        //        judge.setExpertNumber(declareJudge.getExpertNumber());
        judge.setManagementType(declareJudge.getManagementType());
        return AjaxResult.success(declareJudgeService.selectDeclareJudgeList(judge));
    }

    /**
     * 获取排名详细信息
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:ranking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(declareRankingService.selectDeclareRankingById(id));
    }

    /**
     * 新增排名
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:ranking:add')")
    @Log(title = "排名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeclareRanking declareRanking)
    {
        return toAjax(declareRankingService.insertDeclareRanking(declareRanking));
    }

    /**
     * 修改排名
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:ranking:edit')")
    @Log(title = "排名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeclareRanking declareRanking)
    {
        return toAjax(declareRankingService.updateDeclareRanking(declareRanking));
    }

    /**
     * 删除排名
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:ranking:remove')")
    @Log(title = "排名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(declareRankingService.deleteDeclareRankingByIds(ids));
    }
}
